1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4 using
UnityEngine.UI;
5 using
UnityEngine.SceneManagement;
6
7 public
class GamePlayController : MonoBehaviour {
8
9     
public static GamePlayController instance;
10
11     
[SerializeField]
12     
private Text scoreText, endScore, bestScore, gameOverText;
13
14     
[SerializeField]
15     
private Button restartGameButton, instructionButton;
16
17     
[SerializeField]
18     
private GameObject pausePanel;
19
20     
[SerializeField]
21     
private GameObject finishPanel;
22
23     
[SerializeField]
24     
private GameObject[] birds;
25
26     
[SerializeField]
27     
private Sprite[] medals;
28
29     
[SerializeField]
30     
private Image medalImage;
31
32     
void Awake() {
33         MakeInstance ();
34         Time.timeScale =
0f;
35     }
36
37
38     
void Start () {
39         
40     }
41
42     
void MakeInstance () {
43         
if (instance == null) {
44             instance =
this;
45         }
46     }
47
48     
public void pauseGame() {
49         
if (BirdScripts.instance != null) {
50             
if (BirdScripts.instance.isAlive) {
51                 pausePanel.SetActive (
true);
52                 finishPanel.SetActive (
false);
53                 gameOverText.gameObject.SetActive (
false);
54                 endScore.text =
"" + BirdScripts.instance.score;
55                 bestScore.text =
"" + GameControllers.instance.GetHighScore();
56                 Time.timeScale =
0f;
57                 restartGameButton.onClick.RemoveAllListeners ();
58                 restartGameButton.onClick.AddListener (() => resumeGame());
59             }
60         }
61     }
62
63     
public void goToMenu() {
64         SceneManager.LoadScene (
"MainMenu");
65     }
66
67     
public void resumeGame() {
68         pausePanel.SetActive (
false);
69         Time.timeScale =
1f;
70     }
71
72     
public void restartGame() {
73         SceneManager.LoadScene (
"GamePlayScene");
74     }
75
76     
public void playGame() {
77         scoreText.gameObject.SetActive (
true);
78         birds [GameControllers.instance.GetSelectedBird ()].SetActive (
true);
79         instructionButton.gameObject.SetActive (
false);
80         Time.timeScale =
1f;
81     }
82                                                                                                                                                                                                                                                                                                 
83     
public void setScore(int score) {
84         scoreText.text =
"" + score;
85     }
86
87     
public void finishGame() {
88         pausePanel.SetActive (
false);
89         finishPanel.SetActive (
true);
90     }
91
92     
public void playerDiedShowScore(int score) {
93         pausePanel.SetActive (
true);
94         finishPanel.SetActive (
false);
95         gameOverText.gameObject.SetActive (
true);
96         scoreText.gameObject.SetActive (
false);
97
98         endScore.text =
"" + score;
99
100         
if (score > GameControllers.instance.GetHighScore ()) {
101             GameControllers.instance.SetHighScore (score);
102         }
103
104         bestScore.text =
"" + GameControllers.instance.GetHighScore ();
105
106         
if (score <= 20) {
107             medalImage.sprite = medals [
0];
108
109         }
else if (score > 20 && score < 40) {
110             medalImage.sprite = medals [
1];
111
112             
if (GameControllers.instance.IsGreenBirdUnlocked () == 0) {
113                 GameControllers.instance.UnlockGreenBird ();
114             }
115
116         }
else {
117             medalImage.sprite = medals [
2];
118
119             
if (GameControllers.instance.IsGreenBirdUnlocked () == 0) {
120                 GameControllers.instance.UnlockGreenBird ();
121             }
122
123             
if (GameControllers.instance.IsRedBirdUnlocked () == 0) {
124                 GameControllers.instance.UnlockRedBird ();
125             }
126         }
127
128         restartGameButton.onClick.RemoveAllListeners ();
129         restartGameButton.onClick.AddListener (() => restartGame ());
130     }
131 }


Gõ tìm kiếm nhanh...